﻿@{
    ViewData["Title"] = "修改密码";
}

<h3>密码修改</h3>
<p class="text-success">@TempData["Message"]</p>
<p class="text-danger">@TempData["Error"]</p>

<form asp-action="DoChangePassword" method="post" class="mt-3" onsubmit="return checkPassword()">
    <div class="row mb-3">
        <label class="col-sm-2 col-form-label">原密码 <span class="text-danger">*</span></label>
        <div class="col-sm-10">
            <input type="password" name="oldPassword" class="form-control" required />
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-sm-2 col-form-label">新密码 <span class="text-danger">*</span></label>
        <div class="col-sm-10">
            <input type="password" name="newPassword" id="newPassword" class="form-control"
                   minlength="6" required placeholder="至少6位" />
        </div>
    </div>

    <div class="row mb-3">
        <label class="col-sm-2 col-form-label">确认新密码 <span class="text-danger">*</span></label>
        <div class="col-sm-10">
            <input type="password" name="confirmNewPassword" id="confirmNewPassword" class="form-control" required />
            <span id="passwordTip" class="text-danger d-none">两次输入的密码不一致</span>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-sm-10 offset-sm-2">
            <button type="submit" class="btn btn-primary">确认修改</button>
            <a href="@Url.Action("Profile")" class="btn btn-secondary ms-2">返回资料页</a>
        </div>
    </div>
</form>

@section Scripts {
    <script>
        // 前端验证密码一致性
        function checkPassword() {
            const newPwd = document.getElementById("newPassword").value;
            const confirmPwd = document.getElementById("confirmNewPassword").value;
            const tip = document.getElementById("passwordTip");

            if (newPwd !== confirmPwd) {
                tip.classList.remove("d-none");
                return false;
            }
            tip.classList.add("d-none");
            return true;
        }
    </script>
}